TackleMcClean 🏅
02/24/2025, 12:47 PMhead
or body
.
Is this possible to control with razor templates?skttl
02/24/2025, 12:54 PM@if (Context.Items.ContainsKey("HasAddedThisBlocksScript") == false) {
@Context.Items.TryAdd("HasAddedThisBlocksScript", true);
<script>
alert("just once please!");
</script>
}
TackleMcClean 🏅
02/24/2025, 1:03 PMTackleMcClean 🏅
02/24/2025, 1:03 PMMike Chambers
02/24/2025, 1:04 PM@Html.RenderPartialViewCss()
in the template head/foot wherever
Html.RequiresPartialCss("~/css/owner/slickslider.css");
in the partial etc..
https://cdn.discordapp.com/attachments/1343564908192600084/1343569193034977391/message.txt?ex=67bdbfd1&is=67bc6e51&hm=d82353955a708450598ad9028e61df20e56e79311d0ace991873029398d2d73e&Mike Chambers
02/24/2025, 1:05 PMTackleMcClean 🏅
02/24/2025, 1:06 PMMike Chambers
02/24/2025, 1:08 PM@RenderSection("bodyEnd", false)
and then in the nested (inheriting) template you have @section bodyEnd { <script>...</script>}
for injecting/overriding that sectionTackleMcClean 🏅
02/24/2025, 1:09 PMJason
02/24/2025, 3:51 PMdefer
attribute. The browser will download, parse, and compile the JS file asynchronously for maximum efficiency then actually execute once HTML is parsed (as if it was inlcuded at the end of the body).
If you're using modern JS in a module (<script src="somefile.js" type="module"></script>
) then it will defer anyway. It will also just load once, however many times you include it in the page - so you can just spam it inline if you like.Dean Leigh
02/27/2025, 7:05 AMJason
02/27/2025, 8:37 AMskttl
02/27/2025, 8:37 AMJason
02/27/2025, 9:07 AMjs
if(condition) { import("some/js-file.js"); }
Luuk Peters (ProudNerds)
03/14/2025, 2:48 PM